/**
 * 
 */
package de.cbf.cam.dsa.inventory.composites;

import java.util.Iterator;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;

import de.cbf.cam.dsa.model.entities.WeaponStyle;

/**
 * @author Nebelritter
 *
 */
public class CompositeChooseWeaponStyle extends Composite {

	private Combo comboStyle;	
	/**
	 * @param parent
	 * @param style
	 */
	public CompositeChooseWeaponStyle(Composite parent, int style) {
		super(parent, style);
		
		GridLayout layout = new GridLayout(1,false);
		setLayout(layout);
		
		comboStyle = new Combo(this, SWT.DROP_DOWN|SWT.READ_ONLY);
		comboStyle.setLayoutData(new GridData(GridData.FILL_BOTH));
	}
	
	public void setPossibleStyles(List<WeaponStyle> styles){
		for (Iterator<WeaponStyle> iterator = styles.iterator(); iterator.hasNext();) {
			WeaponStyle style = (WeaponStyle) iterator.next();
			comboStyle.setData(style.getTalentName(),style);
			comboStyle.add(style.getTalentName());
		}
		if(styles.size()>0){
			comboStyle.select(0);
		}
	}
	
	public WeaponStyle getChosenStyle(){
		int index = comboStyle.getSelectionIndex();
		String styleName = comboStyle.getItem(index);
		Object obj = comboStyle.getData(styleName);
		if (obj instanceof WeaponStyle) {
			WeaponStyle weaponStyle = (WeaponStyle) obj;
			return weaponStyle;
		}
		return null;		
	}
}
